| Filename | (eval 1176)[/usr/share/perl5/CGI/Compile.pm:12] |
| Statements | Executed 0 statements in 0s |
| Eval Invoked At | /usr/share/perl5/CGI/Compile.pm line 12 |
| Sibling evals | 1, 2 |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 38µs | 64µs | CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@2 |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl;sub {local $CGI::Compile::USE_REAL_EXIT = 0; | ||||
| 2 | 5 | 249µs | # spent 64µs (38+25) within CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@2 which was called:
# once (38µs+25µs) by CGI::Compile::_eval at line 2 # spent 117µs making 1 call to File::pushd::pushd
# spent 64µs making 1 call to CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::BEGIN@2
# spent 26µs making 1 call to warnings::unimport
# spent 25µs making 1 call to CGI::Compile::ROOT::home_vagrant_kohaclone_circ_ysearch_2epl::CORE:open
# spent 18µs making 1 call to CGI::initialize_globals | ||
| 3 | #line 1 /home/vagrant/kohaclone/circ/ysearch.pl | ||||
| 4 | #!/usr/bin/perl | ||||
| 5 | |||||
| 6 | # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html) | ||||
| 7 | |||||
| 8 | # Copyright 2007 Tamil s.a.r.l. | ||||
| 9 | # Parts copyright 2010-2012 Athens County Public Libraries | ||||
| 10 | # | ||||
| 11 | # This file is part of Koha. | ||||
| 12 | # | ||||
| 13 | # Koha is free software; you can redistribute it and/or modify it | ||||
| 14 | # under the terms of the GNU General Public License as published by | ||||
| 15 | # the Free Software Foundation; either version 3 of the License, or | ||||
| 16 | # (at your option) any later version. | ||||
| 17 | # | ||||
| 18 | # Koha is distributed in the hope that it will be useful, but | ||||
| 19 | # WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
| 21 | # GNU General Public License for more details. | ||||
| 22 | # | ||||
| 23 | # You should have received a copy of the GNU General Public License | ||||
| 24 | # along with Koha; if not, see <http://www.gnu.org/licenses>. | ||||
| 25 | |||||
| 26 | =head1 ysearch.pl | ||||
| 27 | |||||
| 28 | =cut | ||||
| 29 | |||||
| 30 | use Modern::Perl; | ||||
| 31 | use CGI qw ( -utf8 ); | ||||
| 32 | use C4::Context; | ||||
| 33 | use C4::Auth qw/check_cookie_auth/; | ||||
| 34 | use Koha::Borrowers; | ||||
| 35 | use Koha::DateUtils qw/format_sqldatetime/; | ||||
| 36 | |||||
| 37 | use JSON qw( to_json ); | ||||
| 38 | |||||
| 39 | my $input = new CGI; | ||||
| 40 | my $query = $input->param('term'); | ||||
| 41 | |||||
| 42 | binmode STDOUT, ":encoding(UTF-8)"; | ||||
| 43 | print $input->header( -type => 'text/plain', -charset => 'UTF-8' ); | ||||
| 44 | |||||
| 45 | my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { circulate => '*' } ); | ||||
| 46 | if ( $auth_status ne "ok" ) { | ||||
| 47 | exit 0; | ||||
| 48 | } | ||||
| 49 | |||||
| 50 | my $limit_on_branch; | ||||
| 51 | if ( C4::Context->preference("IndependentBranches") | ||||
| 52 | && C4::Context->userenv | ||||
| 53 | && !C4::Context->IsSuperLibrarian() | ||||
| 54 | && C4::Context->userenv->{'branch'} ) { | ||||
| 55 | $limit_on_branch = 1; | ||||
| 56 | } | ||||
| 57 | |||||
| 58 | my @parts = split( / /, $query ); | ||||
| 59 | my @params; | ||||
| 60 | foreach my $p (@parts) { | ||||
| 61 | push( | ||||
| 62 | @params, | ||||
| 63 | -or => [ | ||||
| 64 | surname => { -like => "%$p%" }, | ||||
| 65 | firstname => { -like => "%$p%" }, | ||||
| 66 | cardnumber => { -like => "$p%" }, | ||||
| 67 | ] | ||||
| 68 | ); | ||||
| 69 | } | ||||
| 70 | |||||
| 71 | push( @params, { branchcode => C4::Context->userenv->{branch} } ) if $limit_on_branch; | ||||
| 72 | |||||
| 73 | my $borrowers_rs = Koha::Borrowers->search( | ||||
| 74 | { -and => \@params }, | ||||
| 75 | { | ||||
| 76 | # Get the first 10 results | ||||
| 77 | page => 1, | ||||
| 78 | rows => 10, | ||||
| 79 | order_by => [ 'surname', 'firstname' ], | ||||
| 80 | }, | ||||
| 81 | ); | ||||
| 82 | |||||
| 83 | my @borrowers; | ||||
| 84 | while ( my $b = $borrowers_rs->next ) { | ||||
| 85 | push @borrowers, | ||||
| 86 | { borrowernumber => $b->borrowernumber, | ||||
| 87 | surname => $b->surname // '', | ||||
| 88 | firstname => $b->firstname // '', | ||||
| 89 | cardnumber => $b->cardnumber // '', | ||||
| 90 | dateofbirth => format_sqldatetime($b->dateofbirth, undef, undef, 1) // '', | ||||
| 91 | address => $b->address // '', | ||||
| 92 | city => $b->city // '', | ||||
| 93 | zipcode => $b->zipcode // '', | ||||
| 94 | country => $b->country // '', | ||||
| 95 | }; | ||||
| 96 | } | ||||
| 97 | |||||
| 98 | print to_json( \@borrowers ); | ||||
| 99 | |||||
| 100 | }; | ||||
| 101 | my $self = shift; | ||||
| 102 | my $exit_val = unpack('C', pack('C', sprintf('%.0f', $rv))); | ||||
| 103 | if ($@) { | ||||
| 104 | die $@ unless ( | ||||
| 105 | ref($@) eq 'ARRAY' and | ||||
| 106 | $@->[0] eq "EXIT\n" | ||||
| 107 | ); | ||||
| 108 | my $exit_param = unpack('C', pack('C', sprintf('%.0f', $@->[1]))); | ||||
| 109 | |||||
| 110 | if ($exit_param != 0 && !$CGI::Compile::RETURN_EXIT_VAL && !$self->{return_exit_val}) { | ||||
| 111 | die "exited nonzero: $exit_param"; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | $exit_val = $exit_param; | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | return $exit_val; | ||||
| 118 | }; | ||||
| 119 | ; |